﻿using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using CSUploadOSUI.ViewModel;

namespace CSUploadOSUI
{
    class FileManagement
    {
        public static void Save(Model item)
        {
            SaveAs(item, @"C:\x.xml");
        }

        public static Model Open(string path)
        {
            var serializer = new XmlSerializer(typeof(Model));
            XmlReader reader =
                new XmlTextReader(
                    new FileStream(path, FileMode.Open));
            return (Model)serializer.Deserialize(reader);

        }

        public static void SaveAs(Model item, string path)
        {
            var serializer = new XmlSerializer(typeof(Model));
            XmlWriter writer =
                new XmlTextWriter(
                    new FileStream(path, FileMode.Create)
                    , Encoding.Unicode);
            serializer.Serialize(writer, item);
        }
    }
}
